package com.sumainfor.wx.tenant.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.wechat.WeChatConfig;
import com.sumainfor.wx.tenant.dao.TctenTenantCouponsMapper;
import com.sumainfor.wx.tenant.feign.MarketFeignClient;
import com.sumainfor.wx.tenant.feign.ZuulFeignClient;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述:
 * 账单相关
 * @Auther: zhlu
 * @Date: 2019/4/28 16:31
 * @Description:
 */
@Service
public class PayBillService {

    @Autowired
    TctenTenantCouponsMapper TctenTenantCouponsMapper;

    @Autowired
    MarketFeignClient MarketFeignClient;

    @Autowired
    ZuulFeignClient ZuulFeignClient;

    /**
     * 功能描述:
     * 根据账单资料房源资料获取房源信息
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/30 12:23
     */
    public Map<String,Object>getTrenantBillHousing(Map<String,Object>params){
        JsonResult jsonResult=MarketFeignClient.getTrenantBillHousing(params);
        if(jsonResult.isSuccess()==false){
            return jsonResult;
        }
        //根据账单资料房源资料获取房源信息
        Map<String,Object>getTrenantBillHousing=(Map<String, Object>)jsonResult.getResult();
        Map<String,Object>CouponsMapper=new HashMap<String,Object>();
        //账单类型  1.房租（合同） 2.公共事业费  3.维修费用
        //4.延期退  5.其他费用  6.退租账单 7.夜间开门
        String BiType=getTrenantBillHousing.get("BiType").toString();
        String CouType=null;//优惠券类型 0.房租 1.公共事业费
        switch (BiType){
            case "1":
                CouType="0";
                break;
            case "2":
                CouType="1";
                break;
        }
        CouponsMapper.put("TenId",params.get("TenId"));
        CouponsMapper.put("CouType",CouType);
        CouponsMapper.put("State",0);
        //获取用户最大优惠券
        Map<String,Object>getTenantCouponsMaxMap=TctenTenantCouponsMapper.getTenantCouponsMaxMap(CouponsMapper);
        if(MapUtils.isNotEmpty(getTenantCouponsMaxMap)){
            getTrenantBillHousing.put("Coupons",getTenantCouponsMaxMap);
        }else{
            getTrenantBillHousing.put("Coupons",null);
        }


        JsonResult<Map<String, Object>> jsonResult2 = ZuulFeignClient.getAreaPayMap(new HashMap<String, Object>() {{
            put("AreaId", getTrenantBillHousing.get("CorId"));//当前归属公司
        }});
        if (jsonResult2.isSuccess() == true) {
            Map<String,Object>getAreaPayMap=jsonResult2.getResult();
            getTrenantBillHousing.put("Account",getAreaPayMap.get("Account"));
            getTrenantBillHousing.put("AccountFile",getAreaPayMap.get("AccountFile"));
        }else {
            getTrenantBillHousing.put("Account", WeChatConfig.DEFAULT_PAY_ACCONUNT);
            getTrenantBillHousing.put("AccountFile",WeChatConfig.DEFAULT_PAY_ACCONUNTFILE);
        }

        return getTrenantBillHousing;
    }


}
